<template>
<el-row class="infoCon">
    <el-col :span="item.span" v-for="(item, index) in columns" :key="index + '.' + item.column">
        <label v-if="!item.slot && !item.toHtml" class="s-scope"><p :style="{width: item.labelWidth || '150px'}">{{ item.label }}</p><p :title="dataSources[item.column]">{{dataSources[item.column]}}</p></label>
        <label v-else-if="item.toHtml" class="s-scope"><p :style="{width: item.labelWidth || '150px'}">{{ item.label }}</p><p v-html="setText(dataSources[item.column])" :title="dataSources[item.column]"></p></label>
        <label v-else-if="item.slot" class="s-scope"><p :style="{width: item.labelWidth || '150px'}">{{ item.label }}</p><p>
            <slot :name="item.slot" :formItem="item"></slot>
        </p></label>
    </el-col>
</el-row>
</template>

<script setup>

const props = defineProps({
  // 参数样例：dataSources: {projectName: '项目名称', projectCode: '项目代码', projectType: '项目类型', projectLevel: '项目登记'}
  dataSources : {
    type: Object,
    default: ()=>({})
  },
  /**
   * columns需要展示在页面上的字段
   * 字段样例[{label: '项目名称', column: 'projectName', span: 8, toHtml: true},....]
   * span： <el-col :span="8"></el-col>
   * toHtml：true会执行v-html="setText"
   * slot：插槽传column的值
  */
  columns: {
    type: Array,
    default: ()=>[]
  }
});

// 多个Name自动换行
const setText = (str) => {
    if(str){
      str = str.split(",").map(item => `<div>${item}</div>`).join("，")
    }
    return str;
}
const { columns, dataSources } = toRefs(props)
</script>

<style lang="scss" scoped>
::v-deep(.form_link_Btn){
  color: var(--el-color-primary);
  margin-right: 10px;
  cursor: pointer;
}
.infoCon{
    border-right: 1px solid #ededed;
}
.infoCon label {
    display: flex;
    align-items: center;
    color: #333;
    font-weight: bold;
    font-size: 12px;
}
.infoCon label p:first-child {
    width: 110px;
    text-align: right;
    font-weight: normal;
    color: #666;
    min-height: 33px;
    line-height: 1.2em;
    background: #f8f8f8;
    padding-right: 10px;
    border: 1px solid #ededed;
    border-bottom: none;
    border-right: none;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-shrink: 0;
    padding: 5px 10px;
    // align-items: flex-start;
}
.infoCon label p:last-child {
    padding: 5px 10px;
    min-height: 33px;
    line-height: 33px;
    flex: 1;
    // text-indent: 10px;
    display: flex;
    align-items: center;
    border: 1px solid #ededed;
    border-bottom: none;
    border-right: none;
    // display: inline-block !important;
    overflow: hidden; /*超出的部分隐藏起来。*/
    white-space: nowrap; /*不显示的地方用省略号...代替*/
    text-overflow: ellipsis; /* 支持 IE */
    // align-items: flex-start;
}
.infoCon {
    p {
        margin: 0 !important;
    }
    width: 100%;
    border-bottom: 1px solid #ededed;
    display: flex;
    align-items: stretch;
    flex-flow:row wrap;
}

label p:first-child {
    padding-right: 10px;
    background-color: #f8f8f8;
    width: 145px;
    text-align: right;
    margin-right: 10px;
    font-weight: normal;
    color: #666;
    border-right: 1px solid #e9e7e7;
    border-left: 1px solid #e9e7e7;
}
.s-scope {
    align-items: stretch !important;
    height: 100%;
    p:nth-child(1) {
        display: flex !important;
        justify-content: flex-end !important;
        height: auto !important;
    }
    p:nth-child(2) {
        overflow: auto !important;
        white-space: inherit !important;
        height: auto !important;
        // min-height: 60px;
        word-break: break-all;
        line-height: normal !important;
        // padding: 10px 5px !important;
        flex-wrap: wrap;
    }
}
</style>